﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>Xmpp: XmppDb.cs Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                C# examples using state machines generated by StateBuilderDotNet
            </h1>
            <h3>
                Xmpp: XmppDb.cs Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">XmppDb.cs</div>  </div>
</div>
<div class="contents">
<a href="_xmpp_db_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿
<a name="l00002"></a>00002 <span class="keyword">namespace </span>StateForge.Examples.XmppChat
<a name="l00003"></a>00003 {
<a name="l00004"></a>00004     <span class="keyword">using</span> System;
<a name="l00005"></a>00005     <span class="keyword">using</span> System.Collections.Generic;
<a name="l00006"></a>00006     <span class="keyword">using</span> System.Linq;
<a name="l00007"></a>00007     <span class="keyword">using</span> System.Text;
<a name="l00008"></a>00008     <span class="keyword">using</span> System.Data.SqlClient;
<a name="l00009"></a>00009     <span class="keyword">using</span> System.Diagnostics;
<a name="l00010"></a>00010     <span class="keyword">using</span> System.Data.Odbc;
<a name="l00011"></a>00011 
<a name="l00012"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html">00012</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html">XmppDb</a>
<a name="l00013"></a>00013     {
<a name="l00014"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#aa5d5e2e48d71c99f89e641a30f68b8ad">00014</a>         <span class="keyword">public</span> <span class="keywordtype">string</span> ConnectionString { <span class="keyword">get</span>; <span class="keyword">set</span>; }
<a name="l00015"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#a06a6f232cd6ca1ef1354f5a670bdfd14">00015</a>         OdbcConnection <a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#a06a6f232cd6ca1ef1354f5a670bdfd14">connection</a>;
<a name="l00016"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#a597aa4e7cbce6779a56b6008e54f4e8d">00016</a>         <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">string</span> traceName = <span class="stringliteral">&quot;Db&quot;</span>;
<a name="l00017"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#a4849b249816d75318c4979e53f5f63f2">00017</a>         <span class="keyword">private</span> <span class="keyword">static</span> TraceSource ts = <span class="keyword">new</span> TraceSource(traceName);
<a name="l00018"></a>00018 
<a name="l00019"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#ac3c28f80903e55f567502a37482ecd1f">00019</a>         <span class="keyword">public</span> <a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html">XmppDb</a>(<span class="keywordtype">string</span> connectionString)
<a name="l00020"></a>00020         {
<a name="l00021"></a>00021             ts.TraceInformation(<span class="stringliteral">&quot;connection string {0}&quot;</span>, connectionString);
<a name="l00022"></a>00022             this.ConnectionString = connectionString;
<a name="l00023"></a>00023         }
<a name="l00024"></a>00024 
<a name="l00025"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#ac979129f15542f301a4107154e52f939">00025</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Open()
<a name="l00026"></a>00026         {
<a name="l00027"></a>00027             this.connection = <span class="keyword">new</span> OdbcConnection(this.ConnectionString);
<a name="l00028"></a>00028             this.connection.Open();
<a name="l00029"></a>00029         }
<a name="l00030"></a>00030 
<a name="l00031"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#a93836b4c9938a865ba604678c5a37e33">00031</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Close()
<a name="l00032"></a>00032         {
<a name="l00033"></a>00033             this.connection.Close();
<a name="l00034"></a>00034         }
<a name="l00035"></a>00035 
<a name="l00036"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#a0b295d0cdb9a37d0aad92aaa868f159f">00036</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> UserRemove(<span class="keywordtype">string</span> user)
<a name="l00037"></a>00037         {
<a name="l00038"></a>00038             <span class="keywordtype">string</span> queryString = <span class="stringliteral">&quot;DELETE FROM users WHERE username=&#39;&quot;</span> + user + <span class="stringliteral">&quot;&#39;;&quot;</span>;
<a name="l00039"></a>00039             ts.TraceInformation(<span class="stringliteral">&quot;UserRemove {0}&quot;</span>, queryString);
<a name="l00040"></a>00040             Query(queryString);
<a name="l00041"></a>00041         }
<a name="l00042"></a>00042 
<a name="l00043"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#a7ea784655786f639fe7002f248001202">00043</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> UserAdd(<span class="keywordtype">string</span> user, <span class="keywordtype">string</span> password)
<a name="l00044"></a>00044         {
<a name="l00045"></a>00045             <span class="keywordtype">string</span> queryString = <span class="stringliteral">&quot;insert into users (username,password) value (&#39;&quot;</span> + user + <span class="stringliteral">&quot;&#39;,&#39;&quot;</span> + password + <span class="stringliteral">&quot;&#39;) ;&quot;</span>;
<a name="l00046"></a>00046             ts.TraceInformation(<span class="stringliteral">&quot;UserAdd {0} &quot;</span>, queryString);
<a name="l00047"></a>00047             Query(queryString);
<a name="l00048"></a>00048         }
<a name="l00049"></a>00049 
<a name="l00050"></a><a class="code" href="class_state_forge_1_1_examples_1_1_xmpp_chat_1_1_xmpp_db.html#a624eeaf08afcb433a6defb3b023415ed">00050</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> Query(<span class="keywordtype">string</span> queryString)
<a name="l00051"></a>00051         {
<a name="l00052"></a>00052             <span class="keywordflow">if</span> (this.connection == null)
<a name="l00053"></a>00053             {
<a name="l00054"></a>00054                 Open();
<a name="l00055"></a>00055             }
<a name="l00056"></a>00056 
<a name="l00057"></a>00057             <span class="keywordflow">try</span>
<a name="l00058"></a>00058             {
<a name="l00059"></a>00059                 var command = <span class="keyword">new</span> OdbcCommand(queryString, connection);
<a name="l00060"></a>00060                 <span class="keywordtype">int</span> row = command.ExecuteNonQuery();
<a name="l00061"></a>00061                 ts.TraceEvent(TraceEventType.Error, 1, <span class="stringliteral">&quot;row: {0}&quot;</span>, row);
<a name="l00062"></a>00062             }
<a name="l00063"></a>00063             <span class="keywordflow">catch</span> (OdbcException exception)
<a name="l00064"></a>00064             {
<a name="l00065"></a>00065                 ts.TraceEvent(TraceEventType.Error, 1, <span class="stringliteral">&quot;error: {0}&quot;</span>, exception.Message);
<a name="l00066"></a>00066             }
<a name="l00067"></a>00067         }
<a name="l00068"></a>00068     }
<a name="l00069"></a>00069 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
